package pl.ptemich.eav.sprites;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import pl.ptemich.eav.engine.Point;
import pl.ptemich.eav.engine.physics.ShapeParameters;
import pl.ptemich.eav.engine.physics.impl.RectangleParameters;
import pl.ptemich.eav.engine.physics.impl.StaticObjectImpl;
import pl.ptemich.eav.engine.render.Drawable;
import pl.ptemich.eav.engine.render.RenderOptions;
import pl.ptemich.eav.engine.render.Renderer;
import pl.ptemich.eav.engine.render.impl.BaseRenderer;

public abstract class AbstractStaticTile implements Drawable {
 
  private StaticObjectImpl staticPhysic;
  
  private Renderer renderer;
  
  public AbstractStaticTile(float worldPosX, float worldPosY, String resourcePath) throws SlickException {
    // TODO add images loader
    Image image = new Image(resourcePath);
    renderer = new BaseRenderer(image);
    staticPhysic = createObjectPhysic(new Point(worldPosX, worldPosY), image.getWidth(), image.getHeight());
  }
  

  protected StaticObjectImpl createObjectPhysic(Point worldPosition, int width, int height) {
    ShapeParameters shapeParams = new RectangleParameters(width, height);
    return new StaticObjectImpl(worldPosition, width / 2, height / 2, shapeParams);    
  }
  
  @Override
  public void render(RenderOptions options) {
    renderer.render(options, staticPhysic);
  }

  public StaticObjectImpl getStaticPhysic() {
    return staticPhysic;
  }

}
